<template>
	<view>
		<navbar></navbar>
		<view class="container">
			<swiper style="height: 528rpx;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
				:circular="true">
				<swiper-item v-for="(item,index) in data.info.banner_list" :key="index">
					<view class="swiper-item">
						<img :src="item.file_path" alt="">
					</view>
				</swiper-item>
			</swiper>
			<view class="warp-info">
				<view class="name">
					{{data.info.goods_name}}
				</view>
				<view class="detail">
					<view class="stock_num">
						剩余{{data.info.stock_num}}份
					</view>
					<view class="money">
						{{data.info.goods_price}}能量
					</view>
				
				</view>
			</view>
			

			<!-- <view class="division"></view> -->
			<view class="introduce">
				<view class="title">
					商品介绍
				</view>
				<view class="introduce-img">
					<mp-html :content="html"></mp-html>
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="btn" v-if="!isBtn">
				{{btnText}}
			</view>
			<view class="btn1" v-else @click="nav_purchase(goods_id)">
				立即兑换
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				goods_id: null,
				data: [],
				html: '',
				isBtn: false,
				btnText: '',
				is: 0,
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			this.goods_id = options.goods_id
			this.is = options.is
			this.getBankList()
			console.log(Date.parse(new Date()) / 1000)
		},
		onShow() {

		},
		onPullDownRefresh() {
			console.log('下拉刷新')
			this.getBankList(()=>{
				uni.stopPullDownRefresh();
			})
			
		},
		
		mounted() {


		},
		methods: {
			getBankList() {
				let _this = this
				app._post_form('Jadegoods/getDetails', {
					goods_id: _this.goods_id
				}, function(result) {
					if (1 == result.code) {
						console.log(result)
						_this.data = result.data
						_this.html = _this.escape2Html(_this.data.info.content)
						_this.btnStatus(result.data)
					}
				}, null, function() {
					// 解除按钮禁用
					uni.stopPullDownRefresh();
					// app.showError(result.msg);
					
				});
			},
			btnStatus(e) {
				let _this = this

				if (e.start_time < Date.parse(new Date()) / 1000) {
					if (e.end_time > Date.parse(new Date()) / 1000) {
						if (e.is_stop == 1) {
							_this.isBtn = false
							_this.btnText = '已售罄'
						} else {
							if (_this.is == 1) {
								if (e.is_can_buy == 1) {
									_this.isBtn = true
									_this.btnText = '立即兑换'
								} else {
									_this.isBtn = false
									_this.btnText = '兑换次数上限'
								}
							} else {
								_this.isBtn = false
								_this.btnText = '能量不足'
							}
						}
					} else {
						_this.isBtn = false
						_this.btnText = '活动已结束'
					}


				} else {
					_this.isBtn = false
					_this.btnText = this.getDate(e.start_time) + ' 开启兑换'
				}
			},
			//时间戳转换 注：后端返回10位时间戳，需*1000转换
			getDate(date) {
				var t = new Date(date * 1000).toLocaleString();
				return t;
			},
			nav_purchase(e) {
				uni.navigateTo({
					url: `./purchase?goods_id=${e}`
				});
			}

		}
	}
</script>

<style lang="scss">
	page {
		background-color: #080808;
	}
	.container {
		background-color:#080808;
		
		.warp-info{
			margin: 32rpx;
			margin-top: -80rpx;
			position: relative;
			background: #151517;
			border-radius: 8rpx;
			.name{
				font-size: 30rpx;
				color: #FFFFFF;
			}
			.detail{
				.stock_num{
					font-size: 26rpx;
					color: #9A9A9A;
				}
				.money{
					font-size: 30rpx;
					color: #D5B05A;
				}
			}
		}
	}

	.swiper-item {
		width: 100%;
		height: 100%;

		img {
			width: 100%;
			height: 100%;
			object-fit: cover !important;
		}
	}

	.detail {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: -20rpx;

		.stock_num {
			padding: 16rpx 40rpx;
			font-size: 26rpx;
			color: $uni-text-color-active
		}
	}

	.name {
		padding: 16rpx 32rpx;
		// height: 88rpx;
		letter-spacing: 2rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
	}

	.money {

		padding: 16rpx 32rpx;
		font-size: 38rpx;
		font-weight: bold;
		color: $uni-text-color-active;
	}

	.division {
		width: 100%;
		height: 16rpx;
		background-color: #e7e7e7;
	}

	.introduce {
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		padding: 16rpx 32rpx;

		.title {
			margin-top: 10rpx;
			margin-bottom: 40rpx;
			font-weight: bold;
			font-size: 32rpx;
			color: #FFFFFF;
		}
		.introduce-img{
			color: #fff;
			min-height: 50vh;
			background-image: url(@/static/infoImg.png);
			background-size: 100% 100%;
			padding: 10rpx;
			// display: flex;
			// justify-content: center;
			// align-items: center;
			margin-bottom: 100rpx;
		}
	}

	.bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-shadow: 0rpx -1rpx 8rpx 0rpx rgba(0, 0, 0, 0.0600);

		.btn1 {
			margin: 16rpx 28rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			// background: #EDB03B;
			border-radius: 92rpx;
			font-size: 32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color:#000001;
			background: linear-gradient( #FFF4D7,#D8B255);
		}

		.btn {
			margin: 16rpx 28rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background: #999;
			border-radius: 92rpx;
			font-size: 32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
		}
	}
</style>
